<?php
/**
 * Created by PhpStorm.
 * User: WenQing
 * Date: 2017/7/14
 * Time: 16:07
 */
require_once __DIR__ . '/../vendor/autoload.php';
use Workerman\Worker;

// Create a Websocket server
$ws_worker = new Worker("tcp://0.0.0.0:2345");

// 4 processes
$ws_worker->count = 4;

// Emitted when new connection come
$ws_worker->onConnect = function($connection)
{
    echo "New connection\n";
};

// Emitted when data received
$ws_worker->onMessage = function($connection, $data)
{
    // Send hello $data
    echo $data;
    $connection->send('hello ' . $data);
};

// Emitted when connection closed
$ws_worker->onClose = function($connection)
{
    echo "Connection closed\n";
};

// Run worker
Worker::runAll();
